package com.dhq.myapp.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.dhq.myapp.presenter.base.MvpPresenter

/**
 * DESC
 * Created by douhaoqiang on 2025/10/16.
 */
abstract class BaseFragment : Fragment(){

    private lateinit var mvpPresenterImls: ArrayList<MvpPresenter<*>>

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(getLayoutId(), container, false)
    }

    fun addPresenter(presenterIml: MvpPresenter<*>) {
        if (mvpPresenterImls == null) {
            mvpPresenterImls = ArrayList<MvpPresenter<*>>()
        }
        mvpPresenterImls.add(presenterIml)
    }

    fun cleanPresenter() {
        if (mvpPresenterImls != null && !mvpPresenterImls.isEmpty()) {
            val size: Int = mvpPresenterImls.size
            for (i in 0..<size) {
                val mvpPresenterIml: MvpPresenter<*> = mvpPresenterImls.get(i)

                mvpPresenterIml.detachView(false)
            }
        }
    }



    protected abstract fun getLayoutId(): Int

}